package com.smart.service.impl;

import java.util.List;
import java.io.Serializable;
import com.smart.service.BaseService;
import com.smart.util.Pageable;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

public class BaseServiceImpl<T extends Serializable,ID extends Serializable> 
	extends ServiceImpl<BaseMapper<T>,T> implements BaseService<T,ID>{

	/**
	 * @param id 
	 * @see 根据id查询当前实体类
	 **/
	@Override
	public T findById(ID id) {
		return this.baseMapper.selectById(id);
	}

	public com.smart.util.Page<T> findPage(Pageable pageable,
			LambdaQueryWrapper<T> wrapper) {
		int page = pageable.getPage();
		int limit= pageable.getLimit();
		IPage<T> iPage = page(new Page<T>(page,limit),wrapper);
		return new com.smart.util.Page<T>
			(iPage.getRecords(),pageable,iPage.getTotal());
	}

	@Override
	public int update(T t) {
		return this.baseMapper.updateById(t);
	}

	@Override
	public boolean saveEntity(T t) {
		return save(t);
	}

	@Override
	public boolean updateEntity(T t) {
		return updateById(t);
	}

	@Override
	public boolean deleteById(ID id) {
		return removeById(id);
	}

	@Override
	public List<T> findAll() {
		LambdaQueryWrapper<T> wrapper=new LambdaQueryWrapper<T>();
		return this.baseMapper.selectList(wrapper);
	}

	
}